package com.qf.blog.commons.security;

import com.qf.blog.entity.User;
import com.qf.blog.vo.UserToken;

public class UserTokenThreadLocal {

    private static ThreadLocal<UserToken> userTokenThreadLocal = new ThreadLocal<>();

    public static void set(UserToken userToken) {
        userTokenThreadLocal.set(userToken);
    }

    public static UserToken get() {
        return userTokenThreadLocal.get();
    }

    public static User getUser() {
        UserToken userToken = UserTokenThreadLocal.get();
        User user = new User();
        user.setId(userToken.getUserId());
        user.setUsername(userToken.getUsername());
        return user;
    }

    public static void remove() {
        userTokenThreadLocal.remove();
    }
}
